package com.ddtech.business.practice.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ddtech.business.practice.dto.QueAndOptDto;
import com.ddtech.business.practice.entity.PracticeUserAnswer;
import com.ddtech.business.practice.entity.PracticeUserQuestion;
import com.ddtech.business.practice.mapper.PracticeUserAnswerMapper;
import com.ddtech.business.practice.mapper.PracticeUserQuestionMapper;
import com.ddtech.business.practice.query.PracticeUserAnswerQuery;
import com.ddtech.business.practice.service.PracticeService;
import com.ddtech.business.practice.service.PracticeUserAnswerService;
import com.ddtech.utils.PageUtil;
import com.ddtech.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 练习用户答案 服务实现类
 * </p>
 *
 * @author bin_pu
 * @since 2023-05-26
 */
@Service
public class PracticeUserAnswerServiceImpl extends ServiceImpl<PracticeUserAnswerMapper, PracticeUserAnswer> implements PracticeUserAnswerService {
    @Resource
    private PracticeUserQuestionMapper practiceUserQuestionMapper;
    @Autowired
    private PracticeService practiceService;

    @Override
    public Object getErrorPageList(PracticeUserAnswerQuery practiceUserAnswerQuery) {
        IPage<PracticeUserQuestion> errorPageList = practiceUserQuestionMapper.getErrorPageList(practiceUserAnswerQuery.populatePage(), practiceUserAnswerQuery.getQuestionName(), SecurityUtils.getUserId());
        List<PracticeUserQuestion> records = errorPageList.getRecords();
        List<QueAndOptDto> typeQuestion = practiceService.getTypeQuestion(SecurityUtils.getUserId(), records);
        return PageUtil.toPage(typeQuestion, errorPageList.getTotal());
    }
}
